home *** CD-ROM | disk | FTP | other *** search
/ Graphics Plus / Graphics Plus.iso / general / modelers / geomview / source.lha / Geomview / src / lib / mib / mibScrollBar.c < prev    next >
Encoding:
C/C++ Source or Header  |  1993-09-17  |  3.4 KB  |  151 lines

  1. #include "mibload.h"
  2. #include "mibwidgets.h"
  3.  
  4. extern Display    *dpy;
  5. extern GC     mib_gc;
  6.  
  7. /* Code for ScrollBars */
  8. /*****************************************************************************/
  9.  
  10. mib_Widget *mib_create_ScrollBar(mib_Widget *parent, char *name, char *orient,
  11.         int posx, int posy, int width, int height, int mib_fill)
  12. {
  13.   mib_Widget    *temp;
  14.   mib_ScrollBar *myres;
  15.   Arg         args[20];
  16.   int         n;
  17.  
  18.   /* create the new widget and add it to the tree */
  19.  
  20.   temp = mib_new_mib_Widget();
  21.   if (mib_fill == WDEFAULT)
  22.     mib_add_backward(temp, parent);
  23.   else
  24.     mib_add_mib_Widget(temp, parent);
  25.  
  26.   myres = (mib_ScrollBar *)malloc(sizeof(mib_ScrollBar));
  27.  
  28.   /* initialize public resources */
  29.  
  30.   if (mib_fill == WDEFAULT)
  31.   {
  32.     temp->name = (char *)malloc(strlen(name)+1);
  33.     strcpy(temp->name,name);
  34.   }
  35.   temp->mib_class = (char *)malloc(10);
  36.   sprintf(temp->mib_class,"ScrollBar");
  37.   temp->mib_class_num = MIB_SCROLLBAR;
  38.   temp->width = width;
  39.   temp->height = height;
  40.   temp->topOffset = posy;
  41.   temp->leftOffset = posx;
  42.   temp->bottomOffset = 0;
  43.   temp->rightOffset = 0;
  44.   temp->topAttachment = 1;
  45.   temp->leftAttachment = 1;
  46.   temp->bottomAttachment = 0;
  47.   temp->rightAttachment = 0;
  48.  
  49.   temp->mib_allowresize = 1;
  50.  
  51.   /* initialize private resources */
  52.  
  53.   temp->myres = (void *)myres;
  54.   myres->orientation = 0;
  55.  
  56.   /* create Xt widget */
  57.  
  58.   n = 0;
  59.  
  60.   if (mib_fill == WDEFAULT)
  61.   {
  62.     XtSetArg (args[n], XmNleftAttachment, XmATTACH_FORM); n++;
  63.     XtSetArg (args[n], XmNleftOffset, posx);n++;
  64.     XtSetArg (args[n], XmNtopAttachment, XmATTACH_FORM); n++;
  65.     XtSetArg (args[n], XmNtopOffset, posy);n++;
  66.     XtSetArg (args[n], XmNwidth, width); n++;
  67.     XtSetArg (args[n], XmNheight, height); n++;
  68.   }
  69.  
  70.   XtSetArg (args[n], XmNrubberPositioning, False); n++;
  71.  
  72.   if (mib_fill == WDEFAULT)
  73.     if (!strcmp("VertScrollBar",orient))
  74.     {
  75.       XtSetArg (args[n], XmNorientation, XmVERTICAL); n++;
  76.     }
  77.     else
  78.     if (!strcmp("HorzScrollBar",orient))
  79.     {
  80.       XtSetArg (args[n], XmNorientation, XmHORIZONTAL); n++;
  81.       myres->orientation = 1;
  82.     }
  83.  
  84.   temp->me = XtCreateManagedWidget(name, xmScrollBarWidgetClass,
  85.                 temp->parent->me, args, n);
  86.  
  87.   if (mib_fill == WEDIT || mib_fill == WDEFAULT)
  88.   {
  89.     mib_apply_eventhandlers(temp->me, temp);
  90.   }
  91.  
  92.   return temp;
  93. }
  94.  
  95. void mib_delete_ScrollBar(mib_Widget *this)
  96. {
  97.   mib_ScrollBar *temp = (mib_ScrollBar *)this->myres;
  98.  
  99.   free(temp);
  100. }
  101.  
  102. void mib_save_ScrollBar(mib_Widget *this, FILE *fout)
  103. {
  104.   mib_ScrollBar *temp = (mib_ScrollBar *)this->myres;
  105.  
  106.   fprintf(fout,"orientation: %d\\n\\\n", temp->orientation);
  107. }
  108.  
  109. int mib_load_ScrollBar(mib_Widget *this, mib_Buffer *fin)
  110. {
  111.   mib_ScrollBar *myres;
  112.   unsigned char *label_text;
  113.   char          res[MI_MAXSTRLEN];
  114.   char          val[MI_MAXSTRLEN];
  115.   Arg           args[5];
  116.   int           n;
  117.  
  118.   myres = (mib_ScrollBar *)this->myres;
  119.  
  120.   if (!mib_read_line(fin, res, val))
  121.     return 0;
  122.  
  123.   if (!strcmp(res,"orientation"))
  124.   {
  125.     sscanf(val,"%d",&(myres->orientation));
  126.  
  127.     n = 0;
  128.     switch (myres->orientation) {
  129.         case 0:
  130.         XtSetArg (args[n], XmNorientation, XmVERTICAL); n++;
  131.         break;
  132.         case 1:
  133.         XtSetArg (args[n], XmNorientation, XmHORIZONTAL); n++;
  134.         break;
  135.         default:
  136.         break;
  137.     }
  138.     XtSetValues(this->me, args, n);
  139.   }
  140.   else
  141.     return 0;
  142.  
  143.   if (!mib_read_line(fin, res, val))
  144.     return 0;
  145.  
  146.   if (strcmp(res,"EndWidget"))
  147.     return 0;
  148.  
  149.   return 1;
  150. }
  151.